/*
 * Destination.h
 *
 *  Created on: Mar 15, 2013
 *      Author: nick
 */

#ifndef DESTINATION_H_
#define DESTINATION_H_

#include "../h/LogMessage.h"
#include "../h/Exceptions.h"
#include <fstream>
#include <iostream>


namespace Logging {
	class Destination {
	public:
		virtual void send(LogMessage message) = 0;
		virtual ~Destination() {}
	};

	class LocalDestination : public Destination {
	private:
		std::ostream * output;
		const bool isFile;
	public:
		LocalDestination(std::ostream & output = std::clog) : output(&output), isFile(false) {}
		LocalDestination(const char* fileName) : output(new std::ofstream(fileName, std::ios::out | std::ios::app)), isFile(true) {
			if(!((std::ofstream*)output)->is_open()) {
				//throw std::exception("Can't open log file : " + fileName);
			}
		}
		void send(LogMessage message) {
			*output << message;
			output->flush();
		}
		~LocalDestination() {
			if(isFile) {
				((std::ofstream*)output)->close();
				delete output;
			}
		}
	};

	class RemoteDestination : public Destination {
	public:
		RemoteDestination() {
			throw new NotImplementedException();
		}

	};
}


#endif /* DESTINATION_H_ */
